package com.gets.web.repository;

import com.gets.web.model.CollectEntity;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Modifying;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.query.Param;
import org.springframework.stereotype.Repository;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

/**
 * Created by me675 on 2016/9/20.
 */
@Repository // 添加注解
public interface CollectRepository extends JpaRepository<CollectEntity, Integer> {
    @Modifying // 说明该方法是修改操作
    @Transactional // 说明该方法是事务性操作
    // 定义查询
    // @Param注解用于提取参数
    @Query("update CollectEntity co set co.time=:time where co.id=:id")
    void updateCollectTime(@Param("id") int id, @Param("time") long time);

    @Query("select co from CollectEntity co where co.userId=:userId and co.imageSetId=:imageId")
    List<CollectEntity> isExist(@Param("userId") int userId, @Param("imageId") int imageId);

    @Query("delete from CollectEntity co where co.userId=:userId and co.imageSetId=:imageSetId")
    void delete(int userId,int ImageSetId);
    @Query("delete from CollectEntity co where co.userId=:userId")
    void deleteAll(int userId);

    @Query("select co from CollectEntity co where co.userId=:userId")
    void getCollect(int userId);
}